"use strict";

// 检查表单是否通过验证
function checkForm() {
    var usernameValid = checkUsername();
    var passwordValid = checkUserPwd();
    return usernameValid && passwordValid;
}

// 检查用户名格式
function checkUsername() {
    var inputElement = document.getElementById("usernameInput");
    var value = inputElement.value;
    var messageElement = document.getElementById("usernameMsg");
    var regex = /^[a-zA-Z ][a-zA-Z-0-9]{5,9}$/;

    if (!regex.test(value)) {
        messageElement.innerText = "账号格式错误！";
        return false;
    } else {
        messageElement.innerText = "账号格式正确！";
        messageElement.style.color = "green";
        return true;
    }
}

// 检查密码格式
function checkUserPwd() {
    var inputElement = document.getElementById("userPwdInput");
    var value = inputElement.value;
    var messageElement = document.getElementById("userPwdMsg");
    var regex = /^[a-zA-Z0-9 _\-@#&*]{6,12}$/;

    if (!regex.test(value)) {
        messageElement.innerText = "密码格式错误！";
        return false;
    } else {
        messageElement.innerText = "密码格式正确！";
        messageElement.style.color = "green";
        return true;
    }
}